package com.mellarius.Adaptor;

import java.util.ArrayList;
import java.util.List;
import com.helper.SuperHlp;
import com.mellarius.R;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

public class ReplaceSupersAdaptor extends ArrayAdapter<SuperHlp> {

	List<SuperHlp> supers = new ArrayList<SuperHlp>();
	List<PlanetViewHolder> cbList = new ArrayList<PlanetViewHolder>();
	Context context;
	View convertView;
	int size;

	public ReplaceSupersAdaptor(Context context, List<SuperHlp> resource) {
		super(context, R.layout.inner_fragment_remove_treatment, resource);
		// TODO Auto-generated constructor stub
		this.context = context;
		this.supers = resource;

	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		SuperHlp zuper = (SuperHlp) this.getItem(position);
		TextView name;
		TextView date;
		CheckBox cb;
		if (convertView == null) {
			LayoutInflater inflater = ((Activity) context).getLayoutInflater();
			convertView = inflater.inflate(R.layout.inner_fragment_replace_super, parent, false);
			cb = (CheckBox) convertView.findViewById(R.id.checkBoxReplacaHandles);
			date = (TextView) convertView.findViewById(R.id.textDataReplacaHandle);
			name = (TextView) convertView.findViewById(R.id.textColmeiaReplacaHandle);
			convertView.setTag(new PlanetViewHolder(date,name, cb));
			cb.setOnClickListener(new View.OnClickListener() {
				public void onClick(View v) {
					CheckBox cb = (CheckBox) v;
					SuperHlp zuper = (SuperHlp) cb.getTag();
					if (cb.isChecked()) {
						zuper.setChecked(cb.isChecked());
					} else {
						zuper.setChecked(false);
					}
				}
			});
		} else {
			// Because we use a ViewHolder, we avoid having to call
			// findViewById().
			PlanetViewHolder viewHolder = (PlanetViewHolder) convertView.getTag();
			cb = viewHolder.getCheckBox();
			name = viewHolder.getName();
			date = viewHolder.getDate();

		}
		// Tag the CheckBox with the Hive it is displaying, so that we can
		// access the hive in onClick() when the CheckBox is toggled.
		cb.setTag(zuper);
		// Display hive data
		cb.setChecked(zuper.isChecked());
		date.setText(zuper.getDate());
		name.setText(zuper.getColmeia());
		
		

		return convertView;
	}

	/** Holds child views for one row. */
	private static class PlanetViewHolder {
		private CheckBox checkBox;
		private TextView name;
		private TextView date;

		public PlanetViewHolder(TextView date,TextView name, CheckBox checkBox) {
			this.checkBox = checkBox;
			this.name = name;
			this.date = date;
		}

		public CheckBox getCheckBox() {
			return checkBox;
		}

		public TextView getName() {
			return name;
		}

		public TextView getDate() {
			return date;
		}

	}
}
